import importToCDN from "vite-plugin-cdn-import";

/**
 * 打包相关
 * 注意 prodUrl：使用的是 jsdelivr 还是 unpkg。它们的 path 可能不一致
 * 文章链接：https://blog.csdn.net/qq_34450741/article/details/129766676，使用的是 jsdelivr
 * @description importToCDN https://github.com/mmf-fe/vite-plugin-cdn-import
 * @description cdn 在线引入的 cdn 地址配置。path：https://www.jsdelivr.com/ || https://unpkg.com/
 * @description external 打包时，过滤包导入。参考：https://rollupjs.org/configuration-options/#external
 */
export const buildConfig = {
  cdn() {
    return importToCDN({
      //（prodUrl解释： name: 对应下面modules的name，version: 自动读取本地package.json中dependencies依赖中对应包的版本号，path: 对应下面modules的path，当然也可写完整路径，会替换prodUrl）
      prodUrl: "https://cdn.bootcdn.net/ajax/libs/{name}/{version}/{path}",
      modules: [
        {
          name: "vue",
          var: "Vue",
          path: "vue.global.prod.min.js"
        },
        {
          name: "vue-router",
          var: "VueRouter",
          path: "vue-router.global.min.js"
        },
        {
          name: "vue-i18n",
          var: "VueI18n",
          path: "vue-i18n.runtime.global.prod.min.js"
        },
        // 项目中没有直接安装vue-demi，但是pinia用到了，所以需要在引入pinia前引入vue-demi（https://github.com/vuejs/pinia/blob/v2/packages/pinia/package.json#L77）
        {
          name: "vue-demi",
          var: "VueDemi",
          path: "index.iife.min.js"
        },
        {
          name: "pinia",
          var: "Pinia",
          path: "pinia.iife.min.js"
        },
        {
          name: "element-plus",
          var: "ElementPlus",
          path: "index.full.min.js",
          css: "index.min.css"
        },
        {
          name: "axios",
          var: "axios",
          path: "axios.min.js"
        },
        {
          name: "dayjs",
          var: "dayjs",
          path: "dayjs.min.js"
        },
        {
          name: "echarts",
          var: "echarts",
          path: "echarts.min.js"
        }
      ]
    });
  },
  external: ["vue", "axios", "vue-router", "element-plus", "echarts", "vue-i18n", "sortablejs", "vant"]
};
